package com.liveneo.adapter.mobile.service.impl;

import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.liveneo.adapter.base.entity.PrpmAppVersion;
import com.liveneo.adapter.base.entity.PrpmMobileModel;
import com.liveneo.adapter.base.mapper.PrpmAppVersionMapper;
import com.liveneo.adapter.base.mapper.PrpmMobileModelMapper;
import com.liveneo.adapter.mobile.model.request.VersionRequest;
import com.liveneo.adapter.mobile.service.MobileAppVersionService;
import com.liveneo.adapter.mobile.service.ValidateService;
import com.liveneo.system.base.utils.AppException;

/**
 * 手机版本业务处理实现类
 * 
 * @author wangxx
 * 
 */
@Service
public class MobileAppVersionServiceImpl implements MobileAppVersionService {
//    @Autowired
//    private AppVersionDao appVersionDao;
//    @Autowired
//    private MobileModelDao mobileModelDao;
    @Autowired
    PrpmAppVersionMapper prpmAppVersionMapper;
    @Autowired
    PrpmMobileModelMapper prpmMobileModelMapper;
    @Autowired
    private ValidateService validateService;

//    @Override
//    public PrpmAppVersion getVersion(VersionRequest request) throws AppException {
//        // 校验
//        validateService.validateGetVersion(request);
//        // 获取参数
//        String versionId = request.getVersionId();
//        if (versionId == null) {
//            versionId = request.getVersionCode();
//        }
//        String appType = request.getOs();
//        if (appType == null) {
//            appType = request.getOs();
//        }
////        String systemCode = request.getSystemCode();
//        String phoneNo = request.getTel();
//        if (phoneNo == null || "".equals(phoneNo)) {
//            phoneNo = request.getTel();
//        }
//        String phoneModel = request.getPhoneModel();
//        String systemInfo = request.getSystemInfo();
//        // 检查保存手机型号
//        if (phoneNo != null) {
//            saveMobileModelIfNotExist(phoneModel, phoneNo, systemInfo);
//        }
//        // 返回版本信息
//        return prpmAppVersionMapper.getVersion(versionId, appType, systemCode);
//    }

    /**
     * 如果手机型号表中不存在该数据，保存该数据
     * 
     * @param phoneModel 手机号型号
     * @param phoneNo 电话号码
     * @param systemInfo 系统版本
     */
    private void saveMobileModelIfNotExist(String phoneModel, String phoneNo, String systemInfo) {
        if (!prpmMobileModelMapper.exits(phoneModel, phoneNo, systemInfo)) {
            PrpmMobileModel model = new PrpmMobileModel();
            model.setCreatetime(new Date());
            model.setPhoneModel(phoneModel);
            model.setPhoneNo(phoneNo);
            model.setSystemInfo(systemInfo);
            prpmMobileModelMapper.insert(model);
        }
    }
}
